<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
<title>Background page for PrivaSent Chrome extension</title>

<!-- import needed JS files with helper functions -->
<script type="text/javascript" src="HelperFunctions.js"></script>

<!-- Handle all the logic with Facebook's privacy settings -->
<script type="text/javascript">

//handle message containing the Facebook privacy settings page
chrome.extension.onRequest.addListener(
  function(request, sender, sendResponse) {
    console.log(sender.tab ?
                "from a content script:" + sender.tab.url :
                "from the extension");
//     if (request.greeting == "hello")
//       sendResponse({farewell: "goodbye"});
//     else
//       sendResponse({}); // snub them.
	//parse the text representation of Facebook's privacy settings page to DOM
	var parser = new DOMParser();
	var privacySettingsPage = parser.parseFromString(request.documentAsText,"text/xml");
	var newprivacySettingsPage = ChangeDefaultPrivacySetting(privacySettingsPage);
	//send the new page back to the content script
	sendResponse({newDocAsText:newprivacySettingsPage.documentElement.innerHTML});
	 
      
      
  });

function ChangeDefaultPrivacySetting(privacySettingsPage)
{
	//parse elements on privacy settings page
	var settingsSection = getElementsByClass("phl", privacySettingsPage, "td");
	var inputRadioButton = settingsSection[0].getElementsByTagName("input");
	var checked = inputRadioButton[0].getAttribute("checked");
	//inputRadioButton[0].getAttribute("checked");
	inputRadioButton[0].setAttribute("checked","1");
	inputRadioButton[0].setAttribute("value","40");

	var settingsSection = getElementsByClass("prl", privacySettingsPage, "td");
	var inputRadioButton = settingsSection[0].getElementsByTagName("input");
	var checked = inputRadioButton[0].getAttribute("checked");
	//inputRadioButton[0].getAttribute("checked");
	inputRadioButton[0].setAttribute("checked","0");
	inputRadioButton[0].setAttribute("value","80");
	
	return privacySettingsPage;
}
</script>

</head>
<body>

</body>
</html>